package org.cloudbus.cloudsim.examples.power.parallel.helper;

import java.awt.Dimension;
import java.awt.event.WindowEvent;
import java.util.HashMap;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

public class RuntimeChart extends ApplicationFrame {

	public RuntimeChart(String title, HashMap<String, RuntimeInfo> hashMap) {
		super(title);
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		int i = 0, j = 1;

		while (j < hashMap.size()) {
			dataset.addValue(hashMap.get(String.format("%d%d", i, j))
					.getJobValue(), "Number of Jobs has runtime from a-b days",
					String.format("%d-%d", i, j));
			j++;
			i++;
		}
		dataset.addValue(hashMap.get("Undefined").getJobValue(),
				"Number of Jobs has runtime from a-b days", "Undefined");
		JFreeChart chart = ChartFactory.createBarChart(
				"Statistical Runtime Chart", // chart
				// title
				"Number Of Day", // domain axis label
				"Number Of Job", // range axis label
				dataset, // data
				PlotOrientation.VERTICAL, // orientation
				true, // include legend
				true, // tooltips?
				false // URLs?

				);
		ChartPanel chartPanel = new ChartPanel(chart, false);
		chartPanel.setPreferredSize(new Dimension(900, 500));
		setContentPane(chartPanel);
	}

	@Override
	public void windowClosing(WindowEvent event) {
		// TODO Auto-generated method stub

	}
}
